{# empty Twig template #}
<script type="text/javascript" class="source below">
// Note method 2) and 3) use `one`, this is because if `refresh` is called those events are triggered
$(function () {
	$("#demo2")
		.jstree({ "plugins" : ["themes","html_data","ui"] 
        })
		// 1) the loaded event fires as soon as data is parsed and inserted
		.bind("loaded.jstree", function (event, data) {})
		// 2) but if you are using the cookie plugin or the core `initially_open` option:
		.one("reopen.jstree", function (event, data) { })
		// 3) but if you are using the cookie plugin or the UI `initially_select` option:
		.one("reselect.jstree", function (event, data) { })
                .bind("select_node.jstree", function (event, data) { 
                    //console.log(":)"); 
                    var url=data.rslt.obj.attr("id"); 
                    //console.log(data);
                    $.ajax({type: 'POST', url:url, script:true, cache:true,
                   beforeSend: function(response){ $('#loading').append('<div class="loader"><img src="{{asset('bundles/news/images/loaders/loader.gif')}}" alt=""></div>');},
                   error: function(){ $('#formcontent').html('<div class="nNote nFailure hideit"><p><strong>FAILURE: </strong>Oops sorry. That action is not valid, or our servers have gone bonkers</p></div>');},
                    success: function(response) {
			if (response === "false"){

			}else{
		    
                        $('#formcontent').html(response);
                        
			}
                } });
            
                });

});


</script>
<div class="left" > 
<div class="widget"> 
        <!-- Form    -->

   <form action="{{ path('em_category_edit',{'id': id }) }}" method="post" id="valid" class="mainForm">

     
	 <div class="head" id="loading"><h5 class="iHome">Edit Category</h5> </div>
         {% if status_form!=0 %}
         {% if status_form==1 %}
	 <div class="nNote nSuccess hideit">
                <p><strong>SUCCESS: </strong> Category created.</p>
            </div>
	
	{% elseif status_form==2 %}
	<div class="nNote nWarning hideit">
		<p><strong>FAILURE: </strong> Category cant be assigned itself as parent.</p>
	</div>
         {% elseif status_form==3 %}
	<div class="nNote nWarning hideit">
		<p><strong>FAILURE: </strong> You cannot change the level of this category .</p>
	</div>
         {% elseif status_form==4 %}
	<div class="nNote nWarning hideit">
		<p><strong>FAILURE: </strong> The item selected can't have childs .</p>
	</div>
         {% elseif status_form==5 %}
	<div class="nNote nInformation hideit">
		<p><strong>UPDATED: </strong> The item was updated.</p>
	</div>
         {% endif %}
         {% endif %}
         
	
	 {% block form_row %}
	
	<div class="rowElem">
		
        {{ form_widget(form) }}
	</div>
	<div class="fix"></div>
	{% endblock form_row %}
	<div class="fix"><input type="hidden" name="catid" id="catid"  value="{{ path('em_category_delete',{'id': id }) }}"></div>
	
    <input type="button" value="Delete" class="redBtn submitForm" id="delete_btn">
    <input type="submit" id="update_btn" value="Save category" class="greyishBtn submitForm" />
    <div class="fix"></div>
	

</form>
 
</div>
</div>
<!--Derecho-->
<div class="right"> 
<div class="widget">
    <div class="head" id="opened"><h5>Category directory</h5></div>
    <div id="demo2" class="demo" >

                          {% for key, geo in geography%}
                                {% if geo.level.id==1 %}
                                    <ul><li id="{{ path('em_geography_find', {'id': geo.id}) }}" class="jstree-open">
                                      <a href="#" id="cat" >{{ geo.name}}</a>
                                      {% for geo1 in geography%}
                                            {% if geo1.geoParent!=0%}
                                                {% if geo.id==geo1.geoParent%}
                                                  <ul><li id="{{ path('em_geography_find', {'id': geo1.id}) }}" class="jstree-open">
                                                  <a> {{geo1.name}}</a>
                                                  {% for sgeo in geography%}
                                                    {% if geo1.id==sgeo.geoParent%}
                                                            <ul><li id="{{ path('em_geography_find', {'id': sgeo.id}) }}" class="jstree-open">
                                                            <a> {{sgeo.name}}</a>
                                                            {% for subgeo in geography%}
                                                                {% if sgeo.id==subgeo.geoParent%}
                                                                    <ul><li id="{{ path('em_geography_find', {'id': subgeo.id}) }}" class="jstree-open">
                                                                    <a> {{subgeo.name}}</a>
                                                                    </li></ul>  
                                                                {% endif %}
                                                            {% endfor %}
                                                             </li></ul>  
                                                    {% endif %}
                                                  {% endfor %}
                                                  </li></ul>          
                                                 {% endif%} 
                                            {% endif%}
                                      {% endfor%}
                                      </li></ul>
                                {% endif %}
                            {% endfor %}
    </div>
    </div>
  </div>
<script>
$( "#valid" ).submit(function( event ) {
 var action=$('#valid').attr('action');
 var datos = $(this).serialize();     
 console.log("testing method");
 $.ajax({type: 'POST', url:action, script:true, cache:false,data: datos,
                    beforeSend: function(response){ $('#loading').append('<div class="loader"><img src="{{asset('bundles/news/images/loaders/loader.gif')}}" alt=""></div>');},
                    error: function(response){console.log(response);},
                    success: function(response) {
			if (response === "false"){

			}else{
                       // console.log(response);
                        $('#formcontent').html(response);
                        
			}
                } });
        return false;
 
 
});
$("#delete_btn").click(function(event){

var url=$('#catid').val();
jConfirm('Do you want to delete this category?', 'Delete category', function(response) {
			//jAlert('Confirmed: ' + response, 'Confirmation Results');
                        if(response){
                        $.ajax({type: 'POST', url:url, script:true, cache:false,
                        beforeSend: function(response){ $('#loading').append('<div class="loader"><img src="{{asset('bundles/news/images/loaders/loader.gif')}}" alt=""></div>');},
                        error: function(){ $('#formcontent').html('<div class="nNote nFailure hideit"><p><strong>FAILURE: </strong>Oops sorry. That action is not valid, or our servers have gone bonkers</p></div>');},
                        success: function(response) {
                                 if (response === "false"){

                                 }else
                                 {
                                
                                    $('#formcontent').html(response);

                                 }
                         } });
                        }
                      return false;
                      
		});
        
});
</script>   